﻿@using Microsoft.AspNetCore.Components
@inject NavigationManager navigationManager
@inject AuthenticationStateProvider authStateProvider
@inject AppState appState
@inject IStringLocalizer<Global> L

<AuthorizeView Context="AuthorizeContext">
    <Authorized>
        <MatTooltip Tooltip="@L["Logout"]">
            <MatIconButton Icon="exit_to_app" RefBack="@context" OnClick="LogoutClick"></MatIconButton>
        </MatTooltip>
    </Authorized>
    <NotAuthorized>
        <MatTooltip Tooltip="@L["Login"]">
            <MatIconButton Icon="account_box" RefBack="@context" Link="@BlazorBoilerplate.Constants.Settings.LoginPath"></MatIconButton>
        </MatTooltip>
    </NotAuthorized>
</AuthorizeView>

@code {
    async Task LogoutClick()
    {
        appState.ClearUserProfile();
        await ((IdentityAuthenticationStateProvider)authStateProvider).Logout();

        if (navigationManager.IsWebAssembly())
            navigationManager.NavigateTo(BlazorBoilerplate.Constants.Settings.LoginPath);

    }
}
